package com.tony.atomic;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author tonywang
 * @date 8/15/2018
 */
public class AtomicTest {
    public static AtomicReference<User> atomicUserRef = new AtomicReference<>();
    public static void main(String[] args){
        User user = new User("conan", 15);
        atomicUserRef.set(user);
        User updateUser = new User("shichuan", 123);
        atomicUserRef.compareAndSet(user,updateUser);
        System.out.println(atomicUserRef.get().getOld() + ":" + atomicUserRef.get().getName());
    }
    static class User {
        private String name;
        private int old;

        public User() {
        }

        public User(String name, int old) {
            this.name = name;
            this.old = old;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getOld() {
            return old;
        }

        public void setOld(int old) {
            this.old = old;
        }
    }
}
